import time


def pytest_terminal_summary(terminalreporter, exitstatus, config):
    '''收集测试结果'''

    total = terminalreporter._numcollected
    passed = len(terminalreporter.stats.get("passed", []))
    failed = len(terminalreporter.stats.get("failed", []))
    error = len(terminalreporter.stats.get("error", []))
    skipped = len(terminalreporter.stats.get("skipped", []))
    duration = time.time() - terminalreporter._sessionstarttime
    deselected = len(terminalreporter.stats.get("deselected", []))  # 过滤的用例数
    # content = "【自动化测试报告】\t\n" \
    #           "用例总数：%s\t\n" \
    #           "执行用例总数：%s \t\n" \
    #           "执行成功数：%s \t\n" \
    #           "执行失败数：%s \t\n" \
    #           "执行ERROR数：%s \t\n" \
    #           "执行SKIP数：%s \t\n" \
    #           "执行成功数：%.2f %%  \t\n" \
    #           "执行时长：%.2f 秒 \t\n" % (
    #           total, total - deselected, passed, failed, error, skipped, passed / (total - deselected) * 100, duration)

    content = "【自动化测试报告】\t\n" \
              "用例总数TestAll:%sqazxswedcvfrtgbnhy\t\n" \
              "执行用例总数%sqazxswedcvfrtgbnhy\t\n" \
              "用例通过TestPass:%sqazxswedcvfrtgbnhy\t\n" \
              "用例失败TestsFail:%sqazxswedcvfrtgbnhy\t\n" \
              "执行ERROR数:%sqazxswedcvfrtgbnhy\t\n" \
              "用例跳过TestSkip:%sqazxswedcvfrtgbnhy\t\n" \
              "执行成功百分数：%.2f %% qazxswedcvfrtgbnhy\t\n" \
              "执行时长：%.2f秒qazxswedcvfrtgbnhy\t\n" % (
              total, total - deselected, passed, failed, error, skipped, passed / (total - deselected) * 100, duration)

    print(content)
    ###后面可以调用钉钉、发邮件等方法